package com.itheima.test2;

import java.io.*;
import java.net.Socket;

/*
客户端：发送数据，接受服务器反馈

 */
public class ClientTest {


    public static void main(String[] args) throws IOException {
        //创建对象
        Socket socket = new Socket("127.0.0.1", 10010);
        //组织数据
        String s = "你瞅啥";
        OutputStream os = socket.getOutputStream();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        // 发送
        bw.write(s);
        bw.flush();
        //写完数据  必须要给一个结束标记
        socket.shutdownOutput();
        //接受对方 的信息
        InputStream is = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s1 = reader.readLine();
        // 查看信息
        System.out.println(s1);


        //释放资源
        socket.close();

    }
}
